package main

func mian() {

}

func leverOrder(root *TreeNode) [][]int {

	if root == nil {
		return [][]int{}
	}

	result := [][]int{}

	var order func(node *TreeNode, level int)
	m := make(map[int][]int) // 一个哈希表存储结构   层数：该层的数字
	// 从第1层开始，第0层自己处理。

	order = func(node *TreeNode, level int) {
		if node == nil {
			return
		}

		var r []int
		if v, ok := m[level]; ok {
			r = v
		} else {
			r = []int{}
		}
		if node.Left != nil {
			r = append(r, node.Left.Val)
		}

		if node.Right != nil {
			r = append(r, node.Right.Val)
		}

		level++
		m[level] = r

		order(node.Left, level)
		order(node.Right, level)
	}

	a := []int{root.Val}
	result = append(result, a)
	order(root, 0)

	for i := 0; i < len(m)-1; i++ {
		result = append(result, m[i+1])
	}
	return result
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}
